package com.ynns.springcloud.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.ynns.springcloud.pojo.Dept;
import java.util.List;

@RestController
@RequestMapping("/consumer/dept")
public class DeptConsumerController {
    //消费者没有service
    //注入
    @Autowired
    //提供多种便捷访问远程http服务的方法,简单的restful服务模版
    // (url,实体:map，Class<T> responseType)
    private RestTemplate restTemplate;

//    private static final String REST_URL_PREFIX="http://localhost:8001";
    //Ribbon 为变量
    private static final String REST_URL_PREFIX="http://COM.YNNS.SPRINGCLOUD-PROVIDER-DEPT";

    @RequestMapping("/add")
    public boolean addDept(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }
    @RequestMapping("/queryById/{id}")
    public Dept queryById(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/queryById/"+id,Dept.class);
    }
    @RequestMapping("/queryAll")
    public List<Dept> queryAll(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/queryAll",List.class);
    }
}
